package com.student.Activitys.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.student.Activitys.R;
import com.student.Activitys.adapter.base.BaseRecyleViewAdapter;
import com.student.Activitys.adapter.viewholder.ScheduleDayViewHolder;
import com.student.Activitys.bean.ScheduleWeekBean;
import com.student.Activitys.utils.Constant;

import java.util.List;

/**
 * 项目名称：智慧校园学生端
 * 类描述：日课表 adapter
 * 创建人：张飞祥
 * 创建时间：2017/9/26 11:14
 * 修改人：张飞祥
 * 修改时间：2017/9/26 11:14
 * 修改备注：
 */
public class ScheduleDayAdapter extends BaseRecyleViewAdapter {


    private Context context;
    private List<ScheduleWeekBean> list;

    public ScheduleDayAdapter(Context context,  List<ScheduleWeekBean> list) {
        super(context, list);
        this.context = context;
        this.list = list;
    }

    @Override
    protected int getLayoutItmeResId() {
        return R.layout.item_day_schedule;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ScheduleDayViewHolder) {

            ScheduleDayViewHolder viewHolder = (ScheduleDayViewHolder) holder;
            //将数据保存在itemView的Tag中，以便点击时进行获取
            viewHolder.itemView.setTag(position);

            viewHolder.tvItemDayNumberTop.setText((position * 2 + 1) + "");     //top    节次 + 1
            viewHolder.tvItemDayNumberBottom.setText((position * 2 + 2) + "");  //bottom 节次 + 2
            /**
             * 判断 是上午还是下午
             */
            if (position > 1) {
                viewHolder.tvItemDayNoonTop.setText("PM");         //显示 下午
                viewHolder.tvItemDayNoonBottom.setText("PM");      //显示下午
            } else {
                viewHolder.tvItemDayNoonTop.setText("AM");         //显示上午
                viewHolder.tvItemDayNoonBottom.setText("AM");      //显示上午
            }
            /**
             * 判断 当前 节次 是否有课
             */
            if (list.get(position).getKCM() != null) {
                viewHolder.layoutItemDayShow.setVisibility(View.VISIBLE);     //显示数据 页面
                viewHolder.tvItemDayNotShow.setVisibility(View.GONE);         //不显示   无数据页面
                viewHolder.ivItemDaySpotTop.setBackgroundResource(R.drawable.item_day_schedule_spot_yes_icon);    //显示 红点
                viewHolder.ivItemDaySpotBottom.setBackgroundResource(R.drawable.item_day_schedule_spot_yes_icon); //显示 红点
                //装填数据
                viewHolder.tvItemDayCourse.setText("课程：" + list.get(position).getKCM());          //课程名称
                viewHolder.tvItemDayClassroom.setText("教室：" + list.get(position).getSKDD() + "室"); //教室
                viewHolder.tvItemDayTeacher.setText("老师：" + list.get(position).getTeacherName()); //上课老师

                //签到状态
                String signStage = list.get(position).getQD_State();

                /**
                 * 判断是否显示已签到
                 */
                if (list.get(position).getSFQD().equals("1")){
                    viewHolder.tvItemDaySign.setVisibility(View.VISIBLE);   //显示已签到
                    if (signStage.equals(Constant.SIGN_YES)){
                        viewHolder.tvItemDaySign.setText("已签到");
                    }
                    if (signStage.equals(Constant.SIGN_LATE)){
                        viewHolder.tvItemDaySign.setText("已签到（迟到）");
                    }
                }

            } else {
                viewHolder.layoutItemDayShow.setVisibility(View.GONE);               //不显示数据 页面
                viewHolder.tvItemDayNotShow.setVisibility(View.VISIBLE);             //显示   无数据页面
                viewHolder.ivItemDaySpotTop.setBackgroundResource(R.drawable.item_day_schedule_spot_no_icon);    //显示 绿点
                viewHolder.ivItemDaySpotBottom.setBackgroundResource(R.drawable.item_day_schedule_spot_no_icon); //显示 绿点
            }

            /**
             * 判断是否请假（显示 labelView）
             */
            if (list.get(position).getSFQJ() != null) {
                viewHolder.labelDaySchedule.setVisibility(View.VISIBLE);
                //请假
                if(list.get(position).getSFQJ().equals("1")) {                          //已经请假
                    viewHolder.labelDaySchedule.setText("已请假");
                    viewHolder.labelDaySchedule.setBgColor(Color.rgb(242,141,145));
                }else if(list.get(position).getSFPJ().equals("1")) {
                    viewHolder.labelDaySchedule.setText("已评价");                      //已经评价
                    viewHolder.labelDaySchedule.setBgColor(Color.rgb(255,182,127));
                }else{
                    viewHolder.labelDaySchedule.setVisibility(View.GONE);              //没有请假、评价
                }
            }
        }
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(View view) {
        return new ScheduleDayViewHolder(view);
    }
}
